#include "BackGround.h"
#include "RSManager.h"
#include "Sprite.h"

BackGround::BackGround(int id)
{
	_map1_effect = RSManager::getInstance()->getSprite(MAP1_EFFECT);
	_map3_effect1 = RSManager::getInstance()->getSprite(MAP3_EFFECT1);
	_map3_effect2 = RSManager::getInstance()->getSprite(MAP3_EFFECT2);
	_map5_effect = RSManager::getInstance()->getSprite(MAP5_EFFECT);
	_sprite = _map1_effect;
	_delay = 0;	
	_mapID = id;
	_draw1 = _draw2 = false;
}


BackGround::~BackGround(void)
{
}

void BackGround::update()
{
	_delay += GAME_TIME;
	switch (_mapID)
	{
	case 1:
		update1();
		break;
	case 3:
		update3();
		break;
	case 5:
		update1();
		break;
	default:
		break;
	}	
}

void BackGround::render()
{
	if(_draw1)
	{
		if(_mapID == 1)
			_map1_effect->Render(D3DXVECTOR2(0, 0));
		if(_mapID == 5)
			_map5_effect->Render(D3DXVECTOR2(0, 0));
		if(_mapID == 3)
			_map3_effect1->Render(D3DXVECTOR2(0, 0));
	}
	if(_draw2)
		_map3_effect2->Render(D3DXVECTOR2(0, 0));
}

void BackGround::update1()
{	
	if(_delay >= 250)	
		_delay = 0;	
	if(_delay >= 0 && _delay <= 125)
		_draw1 = true;
	else	
		_draw1 = false;
}

void BackGround::update3()
{
	if (_delay >= 400)
		_delay = 0;
	if(_delay >= 0 && _delay <= 125)
		_draw1 = true;
	else
	{
		_draw1 = false;
		if(_delay > 125 && _delay <= 250)
			_draw1 = true;
		else
			_draw1 = false;
	}
}
